home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / basictut.arc / A2.TXT < prev    next >
Text File  |  1989-01-07  |  6KB  |  149 lines

  1. -----
  2. INPUT Statement
  3.  
  4.         The |INPUT~ statement allows you to input from the keyboard while the
  5. program is running.  When the computer comes to an INPUT statement, the program
  6. stops, displays a question mark, and waits until you enter a number, then it
  7. continues with the next line.  After the word INPUT you need to place a
  8. variable.
  9.  
  10.         example:  10 INPUT X
  11.  
  12.         You can place a |prompt~ (words, in quotes, to remind you what to
  13. enter) between the word INPUT and the variable.  If a semi-colon follows the
  14. prompt, then a question mark will be displayed after it.  If a comma follows
  15. the prompt, then no question mark will be displayed.
  16. -----
  17. INPUT Statement (continued)
  18.  
  19.         This is what an INPUT statement might look like in a program.
  20.  
  21.                 |10 INPUT "What is X equal to";X~
  22.                 |20 PRINT X;"+ 3 =";X+3~
  23.  
  24.         Try typing in this program, running it and watch what happens.  After
  25. you do that, change the semi-colon in line |10~ to a comma and |RUN~ it.  To
  26. execute the program again for a different variable value, type |RUN~ and put in a
  27. different number when the computer asks for X.
  28. -----
  29. String variables
  30.  
  31.         Variables can represent letters and text as well as numbers.  A
  32. variable representing a string of letters is called a |string variable~.
  33.  
  34.         String variables are written like |numeric~ variables with a trailing
  35. dollar sign.
  36.                 
  37.                 example: |XYZ$~="Greetings from sensible software!"
  38.  
  39.         You can input a string variable just like you did a numeric variable.
  40. Try running this sample program.
  41.  
  42.         |10 INPUT "What is your name";N$~
  43.         |20 PRINT "It's nice to meet you ";N$;", I'm the IBM Personal Computer."~
  44. -----
  45. More on the LET Statement
  46.  
  47.         Now that you can input and output from the computer, let's really make
  48. the computer do something.  Mathematical calculations can be performed in BASIC
  49. with the LET statement you were introduced to in lesson one.  The LET statement
  50. will set a variable equal to some numeric expression.  Here are the basic
  51. |arithmetic operators~ and how they are handled in BASIC.
  52.  
  53.               FORM              DESCRIPTION             EXAMPLES
  54.                 |+~               addition              A|+~B   6|+~12
  55.                 |-~               subtraction           A|-~B   23|-~7
  56.                 |*~               multiplication        A|*~B   3|*~(2-1)
  57.                 |/~               division              A|/~B   (8+2)|/~4
  58.                 |^~               exponentiation        A|^~B   (5*3)|^~2
  59. -----
  60. More on LET (continued)
  61.  
  62.         Here are two specific examples of the LET statement.
  63.  
  64.                 CELSIUS TO FAHRENHEIT CONVERSION
  65.  
  66.                         |10 LET F=1.8*C+32~
  67.  
  68.                 YEARLY INTEREST
  69.  
  70.                         |10 INTEREST=PRINCIPLE*RATE~
  71.  
  72.         Try writing a program that lets you input a Celsius temperature and
  73. have the computer convert it to Fahrenheit and PRINT the result.  (Use the
  74. |INPUT~, |LET~ and |PRINT~ statements.)  Remember, the IBM version of BASIC allows
  75. you to omit the word LET if you wish.
  76. -----
  77. More LET (continued)
  78.  
  79.         Here is one way to write the previous program.
  80.  
  81.                 |10 INPUT "Enter the Celsius temperature.",C~
  82.                 |20 F=1.8*C+32~
  83.                 |30 PRINT F;"Fahrenheit equals";C;"Celsius."~
  84. -----
  85. SAVE Command
  86.  
  87.         You can |SAVE~ a program on a diskette with the SAVE command.  This
  88. will save your program so that you can retrieve and run it again.  You must
  89. have a diskette ready for use to use this command (you can SAVE a few programs
  90. on the BASIC Prof diskette, but you should use a different diskette for large
  91. programs.)
  92.  
  93.         To SAVE a program, type |SAVE"name"~.  The |name~ can be anything you wish,
  94. but must be eight or less characters with no blank spaces.
  95.  
  96.         |Invalid characters are~
  97.  
  98.                         |+ = : ; , . ?~
  99.  
  100.         Type in the following program.  SAVE it with the name "INTEREST" by
  101. typing |SAVE"INTEREST"~.
  102.  
  103.         |10 INPUT "Enter the amount of principle.",PRIN~
  104.         |20 INPUT "What is the interest rate (use decimal)";RATE~
  105.         |30 INTEREST=PRIN*RATE~
  106.         |40 PRINT "$";INTEREST;"on $";PRIN;"at";RATE;"%"~
  107. ------
  108. LOAD Command
  109.  
  110.         The |LOAD~ command retrieves a program from the diskette and |loads~ it
  111. into the computer's memory.  Hopefully you were able to SAVE your program from
  112. the previous page.  The next time you want to use it, type |LOAD"name"~ (in
  113. this case |name~ is |INTEREST~).  Typing LIST will print the program on the screen.
  114.  
  115.         Try the |LOAD~ command now and |LIST~ the program.
  116. ------
  117. NEW Command
  118.  
  119.         The |NEW~ command |deletes~ the program that is currently in memory.
  120. It will also clears all variables.  When you want to begin writing a new
  121. program, you need to clear any old program remaining in the computer's memory.
  122. Otherwise, you may get lines from the old program mixed in with lines from the
  123. new program.
  124.  
  125.         The format for the NEW command is simply type NEW and press return.
  126. Try out the NEW command by typing |LOAD"INTEREST"~, press return and |LIST~
  127. the program.  Now type |NEW~ and press return and try to |LIST~ the program
  128. again.  This will |not~ erase the program from the |diskette~, |only~ from the
  129. computer's |memory~.
  130. -----
  131. End of Lesson Two
  132.  
  133.         One more lesson finished.  These first two lessons are the foundation
  134. for the rest that you will learn.  From this point on, programming really
  135. starts getting fun.  By the end of the next lesson you should be able to write
  136. your own simple games, but only if you understand everything covered so far.
  137. If you don't really understand about variables or the INPUT statement now,
  138. review the first two lessons before you continue with lesson three.
  139.  
  140.     If you are using the BASIC Prof,        |The PC-Prof.~
  141. let me know who you are!  Send your name        |P.O. Box 26~
  142. and address to:                        |Salina, Kansas~
  143.                             |67402-0026~
  144.  
  145.     If you like the Prof, include a contribution ($30 - $50 suggested) to
  146. help support development of additional volumes.  Please copy and share the
  147. Prof. with other IBM P.C. users.
  148. -----
  149.